package tech.yunjing.train.util;


import tech.yunjing.train.common.Constants;

import java.io.Serializable;

/**
 * 该类表示返回给用户的数据和错误信息
 * Created by zlc on 2017/6/8.
 */
public class JsonResult<T> implements Serializable{

    private int state;        //状态
    private String message;   //异常信息
    private T date;           //成功后接收的数据

    public JsonResult() {
        state = Constants.RESPONSE_CODE_200;
        message = Constants.RESPONSE_MESSAGE_200;
    }

    public JsonResult(int state, String message) {
        this.state = state;
        this.message = message;
    }

    public JsonResult(T data){
        state = Constants.RESPONSE_CODE_200;
        message = Constants.RESPONSE_MESSAGE_200;
        this.date = data;
    }


    public JsonResult(Throwable e){
        state = Constants.RESPONSE_CODE_500;
        message = e.getMessage();
    }

    public JsonResult(int state, Throwable e){
        this.state = state;
        this.message = e.getMessage();
    }


    public JsonResult(int state, String message, T data) {
        this.state = state;
        this.message = message;
        this.date = data;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getDate() {
        return date;
    }

    public void setDate(T date) {
        this.date = date;
    }
}






